package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Api(description = "web端api接口")
@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    private ManagerService managerService;

    //带inner表示是内部资源，不允许外部访问
    @ApiOperation(value = "4.查询库存信息&3.查询图片")
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        return managerService.getSkuInfo(skuId);
    }

    @ApiOperation(value = "1.查询一二三级分类")
    @GetMapping("/inner/getBaseCategory/{category3Id}")
    public BaseCategoryView getBaseCategory(@PathVariable Long category3Id){

        return managerService.getBaseCategory(category3Id);
    }

    @ApiOperation(value = "2.查询销售属性值")
    @GetMapping("/inner/getSaleAttrListChecked/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSaleAttrValueChecked(
            @PathVariable("skuId") Long skuId,
            @PathVariable("spuId") Long spuId){
        return managerService.getSaleAttrListChecked(skuId,spuId);
    }

    @ApiOperation(value = "销售属性值组合以及对应库存id")
    @GetMapping("/inner/getValuesSkuJson/{spuId}")
    public Map getValuesSkuJson(@PathVariable Long spuId){
        return managerService.getValuesSkuJson(spuId);
    }

    @ApiOperation(value = "单独查询价格，不走缓存")
    @GetMapping("/inner/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable Long skuId){
        return managerService.getPrice(skuId);
    }

    @ApiOperation(value = "查询三级分类视图集合")
    @GetMapping("/inner/getBaseCategoryList")
    public List<BaseCategoryView> getBaseCategoryList(){
        return managerService.getBaseCategoryList();
    }

    //查询ES索引库所需数据：品牌表&平台属性表
    @ApiOperation(value = "根据id查询品牌表")
    @GetMapping("/inner/getBaseTrademark/{id}")
    public BaseTrademark getBaseTrademark(@PathVariable Long id){
        return managerService.getBaseTrademark(id);
    }
    @ApiOperation(value = "查询商品平台属性表")
    @GetMapping("/inner/getSkuAttrValue/{skuId}")
    public List<SkuAttrValue> getSkuAttrValue(@PathVariable Long skuId){
        return managerService.getSkuAttrValue(skuId);
    }


}
